﻿<%@ Application Language="C#" %>

<script runat="server">

    void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup

    }
    
    void Application_End(object sender, EventArgs e) 
    {
        //  Code that runs on application shutdown

    }
        
    void Application_Error(object sender, EventArgs e) 
    {
        Exception ex = Server.GetLastError();
        Error appException = new Error(ex.GetType().Name, ex.Message, DateTime.Now, stackTrace: ex.StackTrace, additionalDetails: ex.Source);

        /*check if invalid url and redirect without loggin error*/
        if (appException.Message.Contains("The file") &&
                appException.Message.Contains("does not exist") ||
                appException.Message.Contains("File does not exist."))
            Server.Transfer("~/Error/404.aspx", false);

        int logId = 0;
        try
        {
            ErrorLogBLL exceptionUtility = new ErrorLogBLL();
            logId = exceptionUtility.LogException(appException);
        }
        catch
        {

        }
        finally
        {
            Server.ClearError();
            Server.Transfer("~/Error/Oops.aspx?logid=" + logId, false);
        }
        
    }

    void Session_Start(object sender, EventArgs e) 
    {
        // Code that runs when a new session is started

    }

    void Session_End(object sender, EventArgs e) 
    {
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.

    }
       
</script>
